package com.tanhua.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/11/27 23:32
 */

@DubboService
public class UserApiImpl implements UserApi{

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户电话号码查询
     * @param phone
     * @return
     */
    @Override
    public User findByPhone(String phone) {
        LambdaQueryWrapper<User> queueWrapper = new LambdaQueryWrapper<>();
        queueWrapper.eq(User::getMobile, phone);
        User user = userMapper.selectOne(queueWrapper);
        return user;
    }

    /**
     * 添加新用户
     * @param user
     * @return
     */
    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {

        userMapper.updateById(user);
    }

    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }


    @Override
    public User findById(Long id) {

        return userMapper.selectById(id);
    }

    /**
     * 根据环信账号查询user
     * @param huanxinId
     * @return
     */
    @Override
    public User findByHuanxinId(String huanxinId) {

        LambdaQueryWrapper<User> query = new LambdaQueryWrapper<>();
        query.eq(User::getHxUser, huanxinId);
        User user = userMapper.selectOne(query);
        return user;
    }


}
